import tkinter
from tkinter import *
from PIL import Image, ImageTk
from PIL.Image import Resampling

pic_name="/Users/guasen/Pictures/fxw.png"
root=Tk()
# # 设置主窗口区的背景颜色以区别画布区的颜色
root.config(bg='#8DB6CD')
root.title("C语言中文网")
root.geometry('700x700')
root.iconbitmap('/Users/guasen/Pictures/藤本树_w.png')
# # 将画布设置为白色
# cv = Canvas(root,bg='white')
# #并在画布上添加文本
# # 参数说明，前两个参数（x0，y0）参照点，指定文字字符串的左上角坐标
# # anchor 指定了文本的对于参照点的相对位置，以方位来指定,比如 W/E/N/S等
# cv.create_text(30,80,text = "tkinter内置位图预览",fill ='#7CCD7C',anchor = W,font =('微软雅黑',15,'bold'))

# 展示图片，使用 PhotoImage()来加载图片
frame_width = 600
frame_height = 600
img_open = Image.open(pic_name)
origin_weight = img_open.width
origin_height = img_open.height
height_scale = origin_height/frame_height
width_scale = origin_weight/frame_width
scale =height_scale if height_scale > width_scale else width_scale
des_width =int( origin_weight/scale)
des_height = int (origin_height/scale)
img_open = img_open.resize((des_width,des_height),Resampling.LANCZOS)
img_png = ImageTk.PhotoImage(img_open)
# label_img = tkinter.Label(root, image = img_png)
label_img = tkinter.Label(root,bg="white",width=frame_width,height=frame_height)
label_img.config(image=img_png)
label_img.grid(column=0,row=0)
# cv.create_image(30,150,image = img,anchor =W)
# cv.create_text(30,220,text = "图片预览",fill ='#7CCD7C',anchor = W,font =('微软雅黑',15,'bold'))
# cv.pack()
mainloop()